// SharpConsoleCPP.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <time.h>
#include "INoiseGenerator.h"
#include "RandomNoise.h"
#include "ValueNoise.h"
#include "PerlinNoise.h"
#include "SimplexNoise.h"
#include "WorleyNoise.h"

using namespace std;
using namespace SharpLib;


double GetTimeRandom(int width, int height){
	RandomNoise gen = RandomNoise();

	clock_t t1 = clock();

	for (float x = 0; x < width; x++){
		for (float y = 0; y < height; y++){
			float t = gen.Get2D(x, y);
		}
	}

	clock_t t2 = clock();
	double diffa = (t2 - t1) / (double)CLOCKS_PER_SEC * 1000;
	return diffa;
}

double GetTimeValue(int width, int height){
	ValueNoise gen = ValueNoise();

	clock_t t1 = clock();

	for (float x = 0; x < width; x++){
		for (float y = 0; y < height; y++){
			float t = gen.Get2D(x, y);
		}
	}

	clock_t t2 = clock();
	double diffa = (t2 - t1) / (double)CLOCKS_PER_SEC * 1000;
	return diffa;
}

double GetTimePerlin(int width, int height){
	PerlinNoise gen = PerlinNoise();

	clock_t t1 = clock();

	for (float x = 0; x < width; x++){
		for (float y = 0; y < height; y++){
			float t = gen.Get2D(x, y);
		}
	}

	clock_t t2 = clock();
	double diffa = (t2 - t1) / (double)CLOCKS_PER_SEC * 1000;
	return diffa;
}

double GetTimeSimplex(int width, int height){
	SimplexNoise gen = SimplexNoise();

	clock_t t1 = clock();

	for (float x = 0; x < width; x++){
		for (float y = 0; y < height; y++){
			float t = gen.Get2D(x, y);
		}
	}

	clock_t t2 = clock();
	double diffa = (t2 - t1) / (double)CLOCKS_PER_SEC * 1000;
	return diffa;
}

WorleyNoise gen = WorleyNoise();

double GetTimeWorley(int width, int height){
	

	clock_t t1 = clock();

	for (float x = 0; x < width; x++){
		for (float y = 0; y < height; y++){
			float t = gen.Get2D(x, y);
		}
	}

	clock_t t2 = clock();
	double diffa = (t2 - t1) / (double)CLOCKS_PER_SEC * 1000;
	return diffa;
}


void GenerateRandomTest(){
	cout << "<table>" << endl;
	cout << "<tr>" << endl;
	cout << "<td></td>" << endl;
	cout << "<td>300x200</td>" << endl;
	cout << "<td>1024x768</td>" << endl;
	cout << "<td>1600x900</td>" << endl;
	cout << "<td>1280x1080</td>" << endl;
	cout << "</tr>" << endl;

	double at1 = 0;
	double at2 = 0;
	double at3 = 0;
	double at4 = 0;

	for (int i = 0; i < 10; i++){
		cout << "<tr>" << endl;
		double t1 = GetTimeRandom(300, 200);
		at1 += t1;
		double t2 = GetTimeRandom(1024, 768);
		at2 += t2;
		double t3 = GetTimeRandom(1600, 900);
		at3 += t3;
		double t4 = GetTimeRandom(1280, 1080);
		at4 += t4;
		cout << "<td>" << "Sample " << i + 1 << "</td>" << "<td>" << t1 << "</td>" << "<td>" << t2 << "</td>" << "<td>" << t3 << "</td>" << "<td>" << t4 << "</td>" << endl;
		cout << "</tr>" << endl;
	}
	cout << "<td>Average</td>" << "<td>" << at1 / 10 << "</td>" << "<td>" << at2 / 10 << "</td>" << "<td>" << at3 / 10 << "</td>" << "<td>" << at4 / 10 << "</td>" << endl;
	cout << "</table>" << endl;
	cout << "C++ Random Noise" << endl;
}

void GenerateValueTest(){
	cout << "<table>" << endl;
	cout << "<tr>" << endl;
	cout << "<td></td>" << endl;
	cout << "<td>300x200</td>" << endl;
	cout << "<td>1024x768</td>" << endl;
	cout << "<td>1600x900</td>" << endl;
	cout << "<td>1280x1080</td>" << endl;
	cout << "</tr>" << endl;

	double at1 = 0;
	double at2 = 0;
	double at3 = 0;
	double at4 = 0;

	for (int i = 0; i < 10; i++){
		cout << "<tr>" << endl;
		double t1 = GetTimeValue(300, 200);
		at1 += t1;
		double t2 = GetTimeValue(1024, 768);
		at2 += t2;
		double t3 = GetTimeValue(1600, 900);
		at3 += t3;
		double t4 = GetTimeValue(1280, 1080);
		at4 += t4;
		cout << "<td>" << "Sample " << i + 1 << "</td>" << "<td>" << t1 << "</td>" << "<td>" << t2 << "</td>" << "<td>" << t3 << "</td>" << "<td>" << t4 << "</td>" << endl;
		cout << "</tr>" << endl;
	}
	cout << "<td>Average</td>" << "<td>" << at1 / 10 << "</td>" << "<td>" << at2 / 10 << "</td>" << "<td>" << at3 / 10 << "</td>" << "<td>" << at4 / 10 << "</td>" << endl;
	cout << "</table>" << endl;
	cout << "C++ Value Noise" << endl;
}


void GeneratePerlinTest(){
	cout << "<table>" << endl;
	cout << "<tr>" << endl;
	cout << "<td></td>" << endl;
	cout << "<td>300x200</td>" << endl;
	cout << "<td>1024x768</td>" << endl;
	cout << "<td>1600x900</td>" << endl;
	cout << "<td>1280x1080</td>" << endl;
	cout << "</tr>" << endl;

	double at1 = 0;
	double at2 = 0;
	double at3 = 0;
	double at4 = 0;

	for (int i = 0; i < 10; i++){
		cout << "<tr>" << endl;
		double t1 = GetTimePerlin(300, 200);
		at1 += t1;
		double t2 = GetTimePerlin(1024, 768);
		at2 += t2;
		double t3 = GetTimePerlin(1600, 900);
		at3 += t3;
		double t4 = GetTimePerlin(1280, 1080);
		at4 += t4;
		cout << "<td>" << "Sample " << i + 1 << "</td>" << "<td>" << t1 << "</td>" << "<td>" << t2 << "</td>" << "<td>" << t3 << "</td>" << "<td>" << t4 << "</td>" << endl;
		cout << "</tr>" << endl;
	}
	cout << "<td>Average</td>" << "<td>" << at1 / 10 << "</td>" << "<td>" << at2 / 10 << "</td>" << "<td>" << at3 / 10 << "</td>" << "<td>" << at4 / 10 << "</td>" << endl;
	cout << "</table>" << endl;
	cout << "C++ Perlin Noise" << endl;
}


void GenerateSimplexTest(){
	cout << "<table>" << endl;
	cout << "<tr>" << endl;
	cout << "<td></td>" << endl;
	cout << "<td>300x200</td>" << endl;
	cout << "<td>1024x768</td>" << endl;
	cout << "<td>1600x900</td>" << endl;
	cout << "<td>1280x1080</td>" << endl;
	cout << "</tr>" << endl;

	double at1 = 0;
	double at2 = 0;
	double at3 = 0;
	double at4 = 0;

	for (int i = 0; i < 10; i++){
		cout << "<tr>" << endl;
		double t1 = GetTimeSimplex(300, 200);
		at1 += t1;
		double t2 = GetTimeSimplex(1024, 768);
		at2 += t2;
		double t3 = GetTimeSimplex(1600, 900);
		at3 += t3;
		double t4 = GetTimeSimplex(1280, 1080);
		at4 += t4;
		cout << "<td>" << "Sample " << i + 1 << "</td>" << "<td>" << t1 << "</td>" << "<td>" << t2 << "</td>" << "<td>" << t3 << "</td>" << "<td>" << t4 << "</td>" << endl;
		cout << "</tr>" << endl;
	}
	cout << "<td>Average</td>" << "<td>" << at1 / 10 << "</td>" << "<td>" << at2 / 10 << "</td>" << "<td>" << at3 / 10 << "</td>" << "<td>" << at4 / 10 << "</td>" << endl;
	cout << "</table>" << endl;
	cout << "C++ Simplex Noise" << endl;
}

void GenerateWorleyTest(){
	cout << "<table>" << endl;
	cout << "<tr>" << endl;
	cout << "<td></td>" << endl;
	cout << "<td>300x200</td>" << endl;
	cout << "<td>1024x768</td>" << endl;
	cout << "<td>1600x900</td>" << endl;
	cout << "<td>1280x1080</td>" << endl;
	cout << "</tr>" << endl;

	double at1 = 0;
	double at2 = 0;
	double at3 = 0;
	double at4 = 0;

	for (int i = 0; i < 10; i++){
		cout << "<tr>" << endl;
		double t1 = GetTimeWorley(300, 200);
		at1 += t1;
		double t2 = GetTimeWorley(1024, 768);
		at2 += t2;
		double t3 = GetTimeWorley(1600, 900);
		at3 += t3;
		double t4 = GetTimeWorley(1280, 1080);
		at4 += t4;
		cout << "<td>" << "Sample " << i + 1 << "</td>" << "<td>" << t1 << "</td>" << "<td>" << t2 << "</td>" << "<td>" << t3 << "</td>" << "<td>" << t4 << "</td>" << endl;
		cout << "</tr>" << endl;
	}
	cout << "<td>Average</td>" << "<td>" << at1 / 10 << "</td>" << "<td>" << at2 / 10 << "</td>" << "<td>" << at3 / 10 << "</td>" << "<td>" << at4 / 10 << "</td>" << endl;
	cout << "</table>" << endl;
	cout << "C++ Worley Noise" << endl;
}


void RunGenerate(){
	GenerateRandomTest();
	GenerateValueTest();
	GeneratePerlinTest();
	GenerateSimplexTest();
	GenerateWorleyTest();

}

int _tmain(int argc, _TCHAR* argv[])
{

	RunGenerate();
	cin.get();
	return 0;
}
